// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class distanceCheck extends cc.Component {

    @property()
    checkRadius = 200;

    @property(cc.Node)
    checkNode : cc.Node = null;

    isCheck = false;

    update (dt) {
        if(this.isCheck) return;
        let isHide = this.checkNode.getComponent("roleMediator").processWater;
        if(isHide) return;
        let pos1 = cc.v2(this.node.x,this.node.y);
        let pos2 = cc.v2(this.checkNode.x,this.checkNode.y);
        let distance = pos2.sub(pos1).mag();
        if( distance < 300){
            this.isCheck =  true;
            cc.tween(this.node).to(0.3,{
                position : cc.v2(this.checkNode.x,this.checkNode.y)
            }).start();
        }
    }
}
